package com.ttx.http.demo.util;

import cn.hutool.core.io.FileUtil;
import org.springframework.util.StreamUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

/**
 * @author TimFruit
 * @date 19-12-31 上午12:44
 */
public class FileUtils {

    public static String readContent(String classpathFilepath){
        try {

//            File file=FileUtil.file("classpath: "+classpathFilepath);
            File file=new File(Thread.currentThread().getContextClassLoader().getResource(classpathFilepath).getFile());

            String content=StreamUtils.copyToString(new FileInputStream(file), Charset.defaultCharset());
            return content;
        } catch (IOException e) {
            throw new RuntimeException("读取文件"+classpathFilepath+"出错", e);
        }
    }
}
